/**
 * Created by yvdedu.com on 2016/11/10.
 */
!function(){
    var pageCare=1;
    $(function(){
        $(window).scroll(function () {
            if($(window).height() + $(window).scrollTop()>=document.scrollingElement.scrollHeight&&$(window).scrollTop()>0){
                var care=$(".new .ArticlePanel");
                if(care.length!=0&&care.length%30==0){
                    $.post("/getAllArticle",{page:++pageCare},function(o){
                        if(o){
                            setCare(JSON.parse(o));
                        }
                    })
                }
            }
        });
    });
    var model=$(".ArticlePanel.scrollbar.model");
    function setArticle(temp){
        var time=new Date(temp.createTime).toLocaleString();
        var tempCare=model.clone();
        tempCare.find(".authorPhoto").attr("src",temp.user.photo?temp.user.photo:"photo/0.png")
        tempCare.find(".author").attr("href","user"+temp.user.id);
        tempCare.find(".author").text(temp.user.nickName?temp.user.nickName:temp.user.name);
        tempCare.find(".createTime").text("发表时间："+time);
        tempCare.find(".ck").text("查看"+temp.click);
        tempCare.find(".title.at").attr("href","Article"+temp.id);
        tempCare.find(".title.at").text(temp.name);
        tempCare.find(".ArticleContent").html(temp.content);
        tempCare.css("display","block");
        return tempCare;
    }
    function setCare(js){
        for(var i=0;i<js.length;++i){
            $(".content.new").append(setArticle(js[i]));
        }
    }
}();